from composite import composite


def yanghui_1(n):
    """
    计算 n 行 杨辉三角
    :param n: 行数
    :return:
    """
    result = []
    if n == 1:
        result.append([1])
    if n == 2:
        result.append([1])
        result.append([1, 1])
    if n > 2:
        result.append([1])
        result.append([1, 1])
        for row in range(2, n):
            temp = list()
            temp.append(1)

            for column in range(1, row):
                temp.append(result[row - 1][column - 1] + result[row - 1][column])
            result.append(temp)
            temp.append(1)
    return result


def yanghui_2(n):
    """
    计算 n 行 杨辉三角
    :param n: 行数
    :return:
    """
    result = list()
    for i in range(n):
        temp = list()
        for j in range(i + 1):
            temp.append(int(composite(i, j)))
        result.append(temp)
    return result


def print_yanghui(yanghui):
    for i in range(len(yanghui)):
        print(yanghui[i])


if __name__ == '__main__':
    # yanghui = yanghui_1(9)
    # print_yanghui(yanghui)
    yanghui = yanghui_2(9)
    print_yanghui(yanghui)
